/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.module.background.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseWebController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduStudentPeriodDetails;
import com.xci.edu.core.filter.EduStudentPeriodDetailsFilter;
import com.xci.edu.core.service.EduStudentPeriodDetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学员学时明细页面控制器
 * @author 焦元义 jiaoyuanyi@xci96716.com
 * @since 2020-11-24 15:14:37
 */
@Authorize
@Controller
@RequestMapping(value = "/background/eduStudentPeriodDetails")
public class EduStudentPeriodDetailsController extends BaseWebController {
    /** 学员学时明细服务 */
    @Resource private EduStudentPeriodDetailsService eduStudentPeriodDetailsService;

    /** 首页 */
    @GetMapping
    @Authorize(code = "background.eduStudentPeriodDetails")
    public String index() {
        return "background/eduStudentPeriodDetails/index";
    }

    /** 新建页 */
    @GetMapping("/create")
    @Authorize(code = "background.eduStudentPeriodDetails.insert")
    public String create(ModelMap map) {
        createMark(map);
        var entity = new EduStudentPeriodDetails();
        entity.setId(XCI.nextId());
        // entity.setCoursewareId();
        // entity.setCoursewareName();
        // entity.setStudentId();
        // entity.setStudentName();
        // entity.setStudyCategory();
        // entity.setIp();
        // entity.setSignInDateTime();
        // entity.setSignOutDateTime();
        // entity.setPeriod();
        // entity.setOperateDateTime();
        // entity.setOperateDate();
        map.put("entity", entity);
        return "background/eduStudentPeriodDetails/edit";
    }

    /** 编辑页 */
    @GetMapping("/edit")
    @Authorize(code = "background.eduStudentPeriodDetails.update")
    public String edit(String id, ModelMap map) {
        var entity = eduStudentPeriodDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduStudentPeriodDetails/edit";
    }

    /** 详情页 */
    @GetMapping("/details")
    public String details(String id, ModelMap map) {
        var entity = eduStudentPeriodDetailsService.selectById(Long.valueOf(id));
        XCI.checkNotFoundData(entity, id);
        map.put("entity", entity);
        return "background/eduStudentPeriodDetails/details";
    }

    /** 学习页面 */
    @GetMapping("/student_period")
    @Authorize(code = "background.eduStudentPeriodDetails.validate")
    public String studentPeriod(@ModelAttribute String courseType, ModelMap map) {
        EduStudentPeriodDetails entity=new EduStudentPeriodDetails();
        entity.setCourseType(courseType);
        map.put("entity", entity);
        return "background/eduStudentPeriodDetails/student_period";
//        return "background/eduStudentPeriodDetails/test";
    }

//    /** 学习页面  视频*/
//    @GetMapping("/student_period_video")
//    @Authorize(code = "background.eduStudentPeriodDetails.validate")
//    public String studentPeriodVideo(@ModelAttribute EduStudentPeriodDetails entity) {
//        return "background/eduStudentPeriodDetails/student_period_video";
//    }

    /** 表格查询 */
    @ResponseBody
    @PostMapping("/grid")
    @Authorize(code = "background.eduStudentPeriodDetails.select")
    public BoolResult grid(EduStudentPeriodDetailsFilter filter) {
        return BoolResult.success(eduStudentPeriodDetailsService.selectPageList(filter));
    }

    /** 新建保存 */
    @ResponseBody
    @PostMapping("/createSave")
    @Authorize(code = "background.eduStudentPeriodDetails.insert")
    public BoolResult createSave(@ModelAttribute EduStudentPeriodDetails entity) {

        return eduStudentPeriodDetailsService.insert(entity);
    }

    /** 修改保存 */
    @ResponseBody
    @PostMapping("/updateSave")
    @Authorize(code = "background.eduStudentPeriodDetails.update")
    public BoolResult updateSave(@ModelAttribute EduStudentPeriodDetails entity) {
        return eduStudentPeriodDetailsService.update(entity);
    }

    /** 删除 */
    @ResponseBody
    @PostMapping("/delete")
    @Authorize(code = "background.eduStudentPeriodDetails.delete")
    public BoolResult delete(String ids) {
        return eduStudentPeriodDetailsService.delete(ids);
    }

    /** 修改状态 */
    @ResponseBody
    @PostMapping("/status")
    @Authorize(code = "background.eduStudentPeriodDetails.updateStatus")
    public BoolResult status(String id, Integer status) {
        eduStudentPeriodDetailsService.updateStatus(id, XCI.toBool(status));
        return BoolResult.success();
    }

    /** 导出 */
    @GetMapping("/export")
    @Authorize(code = "background.eduStudentPeriodDetails.export")
    public void export(EduStudentPeriodDetailsFilter filter) {
//        XCI.exportExcel(eduStudentPeriodDetailsService.selectList(filter), EduStudentPeriodDetails.class, "学员学时明细列表");
    }
}
